<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="taglibs.jsp" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${path}/static/bootstrap-3.3.7-dist/css/bootstrap.css"/>
<link rel="stylesheet" href="${path}/static/layui/css/layui.css" media="all">
</head>
<body>
	
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
	  <legend>编辑信息</legend>
	</fieldset>
	<form class="layui-form layui-form-pane" id="ajax_form" method="post" onsubmit="return false">
	 
	 <div class="layui-form-item">
	    <label class="layui-form-label">ID</label>
	    <div class="layui-input-block">
	      <input type="text" name="id" autocomplete="off" placeholder="ID" class="layui-input" value="${student.id}">
	    </div>
	  </div>
	 
	  <div class="layui-form-item">
	    <label class="layui-form-label">姓名</label>
	    <div class="layui-input-block">
	      <input type="text" name="name" autocomplete="off" placeholder="姓名" class="layui-input" value="${student.name}">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">年龄</label>
	    <div class="layui-input-inline">
	      <input type="text" name="age" lay-verify="required" placeholder="年龄" autocomplete="off" class="layui-input" value="${student.age}">
	    </div>
	  </div>
	  
	  <div class="layui-form-item" pane="">
	    <label class="layui-form-label">性别</label>
		    <c:if test="${student.gender=='男'}">
		    	<div class="layui-input-block">
			      <input type="radio" name="gender" value="男" title="男" checked="">
			      <input type="radio" name="gender" value="女" title="女" >
		    	</div>
		    </c:if>
		    <c:if test="${student.gender=='女'}">
			    <div class="layui-input-block">
			      <input type="radio" name="gender" value="男" title="男" >
			      <input type="radio" name="gender" value="女" title="女" checked="">
			    </div>
		    </c:if>
	  </div>
	  
	  <div class="layui-form-item">
	    <label class="layui-form-label">生日</label>
	    <div class="layui-input-inline">
	  		<fmt:setLocale value="zh_cn" />  
	  		<fmt:formatDate value="${student.birthday}" pattern="yyyy-MM-dd" var="birthday" />
<%-- 	        <input type="text" name="birthday" value="${birthday}" lay-verify="required" placeholder="生日" autocomplete="off" class="layui-input" > --%>
	    	<input type="text" name="birthday"  class="layui-input" id="birthdayId" placeholder="yyyy-MM-dd">
	    </div>
	  </div>
	  
	  <div class="layui-form-item">
	    <button class="layui-btn" onclick="submitForm()" value="编辑">编辑</button>
	  </div>
	</form>

	<script src="${path}/static/jquery-1.11.3.js"></script>
	<script src="${path}/static/mylayer.js"></script>
	<script src="${path}/static/util.js"></script>
	<script src="${path}/static/layui/layui.js"></script>
	<script>
	layui.use(['form', 'laydate'], function(){
	  var form = layui.form
	  ,layer = layui.layer
	  ,laydate = layui.laydate;
	  
	  laydate.render({
		  elem: '#birthdayId'
		  ,trigger: 'click'
	  });
	  
	});
	
	function submitForm() {
		
		$.ajax({
			url : "${path}/student/update.action",
			type : "post",
			dataType : "json",
			data : $("#ajax_form").serialize(),
			success : function(jsonObj) {
				console.log(jsonObj);
				if(jsonObj.code == util.SUCCESS) {
					mylayer.successMsg(jsonObj.msg);
					//当你在iframe页面关闭自身时
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					setTimeout(function(){
						parent.layer.close(index); //再执行关闭 
						// 刷新父页面
						window.parent.location.reload();
					},1000);
				} else {
					mylayer.errorMsg(jsonObj.msg);
				}
				
			}
		});
	}
</script>

</body>
</html>